﻿using UnityEngine;
using System.Collections;

public class SettingBar : Popup
{
    public RectTransform hidePos;
    public RectTransform showPos;

    private RectTransform rect;
    public GameObject store;

    private int _sckz;

    // Use this for initialization
    void Start()
    {
        rect = GetComponent<RectTransform>();

        //init ();
        InitShopUi();
    }

    void InitShopUi()
    {
        Debug.Log(gameObject.name);
        if (_sckz == 0 && gameObject.name == "GethPropBar")
        {
            transform.Find("back/Item_random_video").position = transform.Find("back/Item_random_dia").position;
            transform.Find("back/Item_hint_dia").gameObject.SetActive(false);
            transform.Find("back/Item_random_dia").gameObject.SetActive(false);
            transform.Find("back").GetComponent<RectTransform>().sizeDelta = new Vector2(500, 520);
        }
    }

    public void toogle()
    {
        ShowPopup();
    }

    new void ShowPopup()
    {
        if (rect == null)
            rect = GetComponent<RectTransform>();
        iTween.ValueTo(gameObject, iTween.Hash(
            "from", rect.anchoredPosition,
            "to", new Vector2(rect.anchoredPosition.x, showPos.anchoredPosition.y),
            "time", 0.2f,
            "onupdatetarget", this.gameObject,
            "onupdate", "MoveGuiElement"));
    }

    public void MoveGuiElement(Vector2 position)
    {
        rect.anchoredPosition3D = position;
    }

    public new void HidePopup()
    {
        iTween.ValueTo(gameObject, iTween.Hash(
            "from", rect.anchoredPosition,
            "to", new Vector2(rect.anchoredPosition.x, hidePos.anchoredPosition.y),
            "time", 0.2f,
            "onupdatetarget", this.gameObject,
            "onupdate", "MoveGuiElement"));
    }

    public void Pause()
    {
        GameStatic.timeBar.pause();
    }

    public void Resume()
    {
        GameStatic.timeBar.continueRun();
    }

    public void RubyToHint(int price)
    {
        int ruby = Save.getPlayerCoin();
        if (ruby >= price)
        {
            ItemController.addHintItem(price / 10);
            Save.addPlayerCoin(-price);
        }
        else
        {
        }
    }

    public void VideoToHint()
    {

        ItemController.addHintItem(2);

    }


    public void RubyToRandom(int price)
    {
        int ruby = Save.getPlayerCoin();
        if (ruby >= price)
        {
            ItemController.addRandomItem(price / 10);
            Save.addPlayerCoin(-price);
        }
        else
        {

        }
    }

    public void VideoToRandom()
    {

        ItemController.addRandomItem(2);
    }

    public void VideoToTenCoins()
    {
    }
}